#include <vector>
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <stdlib.h>
#include <climits>
#include <limits.h>
#include <math.h>
#include <string>
#include <sstream>
#include "gnuplot.h"

using namespace std;

struct neurons{
	vector<double> weights;
};

struct icone{
	vector<int> conec;
};

struct input{
	vector<double> inp;
};

struct pos{
	int x,y;
};

class SOM{
	private:
		vector<input> inputs;
		vector<neurons> vNeurons;
		vector<icone> vIcone; //Para el dibujo
		vector<pos> vPos;
		vector<int> vClass;
		double eta,eta0,dInit,sigma0,tau1,sigma; //dInit: dimension de entrada
		int epOrder,epTrans,epConv,tau2,x,y,numbInputs,style,stPrint; //tamaño del mapa

		void init();
		double distance(int& rjx,int& rjy,int& rix,int& riy);
		void loadConfig();
		double randomWeight();
		int competency(int& k);
		void Neighborhood(int& p,int& n,int& k,int phase);
		void print(bool classif);
		void saveConectivityFile(int& i,string file);
		void saveWeightsFile(int& i,string file);
		void saveWeightsFile(vector<neurons>& v,string file);
		void normalize();
	public:
		SOM();
		SOM(vector< vector<double> >& v);
		void generate_patterns();
		void ordering_phase(bool classif);
		void transition_phase(bool classif);
		void convergence_phase(bool classif);
		void classification(vector<int>& v);
		void print_patterns();
};
